/*
 * CBIRView.java
 */
package semantic;

import java.awt.Image;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class SemanticView extends FrameView {

    public SemanticView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        searchResultArea = new javax.swing.JPanel();
        imagePreview9 = new javax.swing.JLabel();
        imagePreview8 = new javax.swing.JLabel();
        imagePreview7 = new javax.swing.JLabel();
        imagePreview6 = new javax.swing.JLabel();
        imagePreview5 = new javax.swing.JLabel();
        imagePreview4 = new javax.swing.JLabel();
        imagePreview2 = new javax.swing.JLabel();
        imagePreview1 = new javax.swing.JLabel();
        imagePreview10 = new javax.swing.JLabel();
        imagePreview12 = new javax.swing.JLabel();
        imagePreview13 = new javax.swing.JLabel();
        imagePreview14 = new javax.swing.JLabel();
        jScrollBar1 = new javax.swing.JScrollBar();
        comboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        searchButton = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        openFileMenuItem = new javax.swing.JMenuItem();
        searchMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        fileChooser = new javax.swing.JFileChooser();

        mainPanel.setName("mainPanel"); // NOI18N

        searchResultArea.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Search Result"));
        searchResultArea.setName("searchResultArea"); // NOI18N

        imagePreview9.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview9.setName("imagePreview9"); // NOI18N
        imagePreview9.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview8.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview8.setName("imagePreview8"); // NOI18N
        imagePreview8.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview7.setName("imagePreview7"); // NOI18N
        imagePreview7.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview6.setName("imagePreview6"); // NOI18N
        imagePreview6.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview5.setName("imagePreview5"); // NOI18N
        imagePreview5.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview4.setName("imagePreview4"); // NOI18N
        imagePreview4.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview2.setName("imagePreview2"); // NOI18N
        imagePreview2.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview1.setName("imagePreview1"); // NOI18N
        imagePreview1.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview10.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview10.setName("imagePreview10"); // NOI18N
        imagePreview10.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview12.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview12.setName("imagePreview12"); // NOI18N
        imagePreview12.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview13.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview13.setName("imagePreview13"); // NOI18N
        imagePreview13.setPreferredSize(new java.awt.Dimension(120, 120));

        imagePreview14.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imagePreview14.setName("imagePreview14"); // NOI18N
        imagePreview14.setPreferredSize(new java.awt.Dimension(120, 120));

        jScrollBar1.setName("jScrollBar1"); // NOI18N

        javax.swing.GroupLayout searchResultAreaLayout = new javax.swing.GroupLayout(searchResultArea);
        searchResultArea.setLayout(searchResultAreaLayout);
        searchResultAreaLayout.setHorizontalGroup(
            searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchResultAreaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(imagePreview7, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(imagePreview4, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(imagePreview1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchResultAreaLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, searchResultAreaLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, searchResultAreaLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(imagePreview9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(imagePreview12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(imagePreview13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(imagePreview14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );
        searchResultAreaLayout.setVerticalGroup(
            searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchResultAreaLayout.createSequentialGroup()
                .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchResultAreaLayout.createSequentialGroup()
                        .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(imagePreview13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(16, 16, 16)
                        .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(imagePreview12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(16, 16, 16)
                        .addGroup(searchResultAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(imagePreview14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(imagePreview7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE))
                    .addComponent(jScrollBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
                .addContainerGap())
        );

        comboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Colour Histogram", "CCV", "Correlogram", "Texture", "Segment" }));
        comboBox.setName("comboBox"); // NOI18N
        comboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBoxActionPerformed(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(semantic.SemanticApp.class).getContext().getResourceMap(SemanticView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        searchButton.setText(resourceMap.getString("searchButton.text")); // NOI18N
        searchButton.setFocusable(false);
        searchButton.setName("searchButton"); // NOI18N
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonsearchMenuItemActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tags", "Time", "Location" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(71, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(comboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(searchResultArea, javax.swing.GroupLayout.PREFERRED_SIZE, 622, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(searchButton)
                .addGap(236, 236, 236))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(searchButton)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(searchResultArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setName("fileMenu"); // NOI18N

        openFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        openFileMenuItem.setName("openFileMenuItem"); // NOI18N
        openFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFileMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openFileMenuItem);

        searchMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        searchMenuItem.setName("searchMenuItem"); // NOI18N
        searchMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(searchMenuItem);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(semantic.SemanticApp.class).getContext().getActionMap(SemanticView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 592, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        fileChooser.setFileFilter(new MyCustomFilter() );
        fileChooser.setName("fileChooser"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void openFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFileMenuItemActionPerformed

        int returnVal = fileChooser.showOpenDialog(this.getFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fileChooser.getSelectedFile();
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview.setIcon(new ImageIcon(ImageIO.read(file).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + file.getAbsolutePath());
            }
        } else {
            System.out.println("File access cancelled by user.");
        }

    }//GEN-LAST:event_openFileMenuItemActionPerformed

    private void searchMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchMenuItemActionPerformed
        if (file != null) {
            imageResult = DCT.colorHistogram(file, queryMethod);
            pageSlider.setValue(0);
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview1.setIcon(new ImageIcon(ImageIO.read(imageResult.get(0).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(0).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview2.setIcon(new ImageIcon(ImageIO.read(imageResult.get(1).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(1).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview3.setIcon(new ImageIcon(ImageIO.read(imageResult.get(2).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(2).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview4.setIcon(new ImageIcon(ImageIO.read(imageResult.get(3).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(3).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview5.setIcon(new ImageIcon(ImageIO.read(imageResult.get(4).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(4).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview6.setIcon(new ImageIcon(ImageIO.read(imageResult.get(5).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(5).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview7.setIcon(new ImageIcon(ImageIO.read(imageResult.get(6).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(6).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview8.setIcon(new ImageIcon(ImageIO.read(imageResult.get(7).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(7).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview9.setIcon(new ImageIcon(ImageIO.read(imageResult.get(8).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(8).getFile().getAbsolutePath());
            }
        }
    }//GEN-LAST:event_searchMenuItemActionPerformed

    private void comboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxActionPerformed
        queryMethod = comboBox.getSelectedIndex();
    }//GEN-LAST:event_comboBoxActionPerformed

    private void searchButtonsearchMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonsearchMenuItemActionPerformed
        if (file != null) {
            imageResult = DCT.colorHistogram(file, queryMethod);
            pageSlider.setValue(0);
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview1.setIcon(new ImageIcon(ImageIO.read(imageResult.get(0).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(0).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview2.setIcon(new ImageIcon(ImageIO.read(imageResult.get(1).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(1).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview3.setIcon(new ImageIcon(ImageIO.read(imageResult.get(2).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(2).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview4.setIcon(new ImageIcon(ImageIO.read(imageResult.get(3).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(3).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview5.setIcon(new ImageIcon(ImageIO.read(imageResult.get(4).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(4).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview6.setIcon(new ImageIcon(ImageIO.read(imageResult.get(5).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(5).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview7.setIcon(new ImageIcon(ImageIO.read(imageResult.get(6).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(6).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview8.setIcon(new ImageIcon(ImageIO.read(imageResult.get(7).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(7).getFile().getAbsolutePath());
            }
            try {
                // What to do with the file, e.g. display it in a imagePreview label
                imagePreview9.setIcon(new ImageIcon(ImageIO.read(imageResult.get(8).getFile()).getScaledInstance(120, 120,
                        Image.SCALE_SMOOTH)));
            } catch (IOException ex) {
                System.out.println("problem accessing file" + imageResult.get(8).getFile().getAbsolutePath());
            }
        }
}//GEN-LAST:event_searchButtonsearchMenuItemActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboBox;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JLabel imagePreview1;
    private javax.swing.JLabel imagePreview10;
    private javax.swing.JLabel imagePreview12;
    private javax.swing.JLabel imagePreview13;
    private javax.swing.JLabel imagePreview14;
    private javax.swing.JLabel imagePreview2;
    private javax.swing.JLabel imagePreview4;
    private javax.swing.JLabel imagePreview5;
    private javax.swing.JLabel imagePreview6;
    private javax.swing.JLabel imagePreview7;
    private javax.swing.JLabel imagePreview8;
    private javax.swing.JLabel imagePreview9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollBar jScrollBar1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openFileMenuItem;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JButton searchButton;
    private javax.swing.JMenuItem searchMenuItem;
    private javax.swing.JPanel searchResultArea;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    private File file;
    ArrayList<ImageData> imageResult;
    int queryMethod = 0;
}

class MyCustomFilter extends javax.swing.filechooser.FileFilter {

    @Override
    public boolean accept(File file) {
        // Allow only directories, or files with ".jpg" or ".jpeg" extension
        return file.isDirectory() || file.getAbsolutePath().endsWith(".jpg") || file.getAbsolutePath().endsWith(".jpeg");
    }

    @Override
    public String getDescription() {
        // This description will be displayed in the dialog,
        // hard-coded = ugly, should be done via I18N
        return "JPEG Images (*.jpg)";
    }
}
